{extend name="common/base" /}
{block name='title'}添加模型 - 模型管理{/block}

{block name="body"}
<article class="clearfix pd-20">
    <form action="" method="post" class="form form-horizontal" id="form-admin-add">
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>类型名：</label>
            <div class="form-controls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="model_name" name="model_name">
            </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>模型：</label>
            <div class="form-controls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="model_alias" name="model_alias">
            </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>入口：</label>
            <div class="form-controls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="" placeholder="" id="entrance_action" name="entrance_action">
            </div>
        </div>
        <div class="row clearfix">
            <label class="form-label col-xs-4 col-sm-3">排序：</label>
            <div class="form-controls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="0" placeholder="" id="sort" name="sort">
            </div>
        </div>
        <div class="row clearfix">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
            </div>
        </div>
    </form>
</article>
{/block}

{block name="js"}
<!--请在下方写此页面业务相关的脚本-->

<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="__LIB__/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
    $(function(){
        /* 通过iCheck插件，美化checkbox */
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        /* 表单验证，提交 */
        $("#form-admin-add").validate({
            rules:{
                sys_name:{
                    required:true,
                },
                model_alias:{
                    required:true,
                },
                entrance_action:{
                    required:true,
                },
                sort:{
                    required:true,
                },
               
            },
            
            onkeyup:false,
            focusCleanup:true,
            success:"valid",
            submitHandler:function(form){
                var model_name = $("input[name='model_name']").val();
                var model_alias = $("input[name='model_alias']").val();
                var entrance_action = $("input[name='entrance_action']").val();
                var sort = $("input[name='sort']").val();
               
                $.ajax({
                    type: 'post', // 提交方式 get/post
                    url: "{:url('mould/add')}", // 需要提交的 url
                    data: {
                        'name': model_name,
                        'model_alias': model_alias,
                        'sort': sort,
                        'entrance_action' : entrance_action,
                      
                    },
                    dataType: 'json',
                    success: function(ret) { // data 保存提交后返回的数据，一般为 json 数据
                        // 此处可对 data 作相关处理
                        if(0 == ret.code){
                            layer.msg(ret.msg, { icon:1,time:1000 });
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.location.replace(parent.location.href)
                            parent.layer.close(index);
                        }else{
                            layer.msg(ret.msg, { icon:2,time:1000 });
                        }
                    }
                });
                
            }
        });
    });
</script>
<!--/请在上方写此页面业务相关的脚本-->
{/block}
